﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Project.Database.Repository
{
    public partial class DatabaseRepository
    {
        #region Properties
        #endregion

        #region Query Methods

        public Advertiser GetAdvertiser(int id)
        {
            return entities.Advertisers.SingleOrDefault(adv => adv.ID == id);
        }

        public Advertiser GetAdvertiser(User user)
        {
            return user.Advertiser;
        }

        public Advertiser GetAdvertiser(string BrandName)
        {
            return entities.Advertisers.SingleOrDefault(adv => adv.BrandName == BrandName);
        }

        #endregion

        #region Insert/Delete


        public void UpdateAdvertiser(string username, string brandname, string description, string logoUrl, string website, string address)
        {
            //TODO check input strings
            User user = GetUser(username);

            user.Advertiser.BrandName = brandname;
            user.Advertiser.BrandDescription = description;
            user.Advertiser.BrandLogoURL = logoUrl;
            user.Advertiser.Website = website;
            user.Advertiser.Address = address;
            user.Advertiser.LastModified = DateTime.Now;
            Save();
        }

        #endregion

        #region Helper Methods

        public bool AdvertiserExists(string BrandName)
        {
            return GetAdvertiser(BrandName) != null;
        }

        #endregion
    }
}